<template>
  <el-form
    :model="ruleForm"
    status-icon
    ref="ruleForm"
    label-width="100px"
    class="demo-ruleForm"
  >
    <el-form-item label="姓名" prop="name">
      <el-input
        type="text"
        v-model="ruleForm.name"
      ></el-input>
    </el-form-item>
    <el-form-item label="部门" prop="department">
      <el-input
        type="text"
        v-model="ruleForm.department"
      ></el-input>
    </el-form-item>
    <el-form-item>
      <el-button type="primary" @click="submitForm(ruleForm)">提交</el-button>
      <el-button @click="resetForm(ruleForm)">重置</el-button>
    </el-form-item>
  </el-form>
</template>

<script>
import { addInfo } from "@/api/info.api"
export default {
  data() {
    return {
      ruleForm: {
        name: "",
        department: ""
      }
    };
  },
  methods: {
    submitForm(formName) {
      let _this = this
      addInfo(formName).then((response) => {
        if(response.status === 201){
            _this.$alert("添加成功",'addInfo')
            _this.$router.push('/')
        }
      })
    },
    resetForm(formName) {
      this.$refs[formName].resetFields();
    },
  },
};
</script>
